<template>
    <div class="listDiv pd20">
        <div class="searchDiv">
            <el-form class="searchLeft" ref="serform" :model="obj.req" label-position="top">
                <el-form-item class="mr20 mb10">
                    <span class="btn add" @click="add">添加部门</span>
                </el-form-item>
                <el-form-item class="serlabelB mr20 mb10" label="部门名称：" prop="key">
                    <el-input v-model="obj.req.key" placeholder="请输入部门名称" class="search_key" clearable />
                </el-form-item>
                <span class="btn search mb10 mr5" @click="obj.req.currentpage=1;init()">查询</span>
                <span class="btn refresh mb10" @click="proxy.$refs['serform'].resetFields();init()">重置</span>

                <el-form-item class="serlabelB mr20 mb10 ml20" label="配置所属局：" prop="configf">
                    <el-input v-model="obj.configf" autocomplete="off"></el-input>
                </el-form-item>
                <span class="btn search mb10 mr5" @click="configSubmit">确认</span>
            </el-form>
        </div>
        <div class="table" id="tb">
            <ul class="head">
                <li class="liflex">所属局</li>
                <li class="liflex">部门id</li>
                <li class="liflex">部门名称</li>
                <li class="liaction liflex">操作</li>
            </ul>
            <div class="body">
                <ul v-for="x in obj.ary" :key="x">
                    <li class="liflex flex-center">{{obj.config}}</li>
                    <li class="liflex flex-center">{{x.dept_id}}</li>
                    <li class="liflex flex-center">{{x.name}}</li>
                    <li class="liaction liflex flex-center">
                        <u @click.prevent="edit(x)">编辑</u>
                        <DelConfirm @yesClick="del(x)" />
                    </li>
                </ul>
            </div>
        </div>
    </div>
</template>

<script setup>
    import { reactive,getCurrentInstance,onActivated } from 'vue'
    import Pager from '@/components/pager.vue'
    import DelConfirm from '@/components/del_confirm.vue'
    import Edit from './edit.vue'
    let { proxy } = getCurrentInstance()

    let obj = reactive({
        ary:[],
        req:{key:''},
        config: '',
        configf: ''
    })

    onActivated(()=>{
        init()
        getconfig()
    })

    const getconfig=()=>{
        proxy.$ajax({
            url: '/manager/config/get',
            data: {},
            bfLoading: true
        }).then(d => {
            if(d.success){
                obj.config = d.msg||''
                obj.configf = d.msg||''
            }
        }).catch(() => {})
    }

    let init = () => {
        proxy.$ajax({
            url: '/manager/department/list',
            data: obj.req,
            bfLoading: true
        }).then(d => {
            if(d.success){
                obj.ary = d.msg.list
            }
        }).catch(() => { })
    }

    let add = () => {
        proxy.routerPushMixin("/departEdit",{})
    }

    let edit = x => {
        proxy.routerPushMixin("/departEdit",{id:x.dept_id,name:x.name})
    }

    let del = x => {
        proxy.$ajax({
            url: '/manager/department/delete',
            data: { dept_id: x.dept_id },
            bfLoading: true
        }).then(d => {
            if(d.success){
                proxy.elMessageMixin("删除成功", 'success')
                init()
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }

    const configSubmit=()=>{
        proxy.$ajax({
            url: '/manager/config/design',
            data: {name: obj.configf},
            bfLoading: true
        }).then(data => {
            if(data.success){
                proxy.elMessageMixin(`配置成功`, 'success')
                getconfig()
            }else{
                ElMessage({ message: data.err, type: 'error', duration: 2 * 1000 })
            }
        }).catch(() => {})
    }
</script>

<style scoped>
</style>